#include <fcntl.h>
#include <stdio.h>
#include <string.h>

int main()
{
	int fd = open("dup.dat",O_CREAT | O_RDWR ,0666);
	int fd2 = dup(fd);
	printf("fd = %d , fd2 = %d\n" , fd , fd2);
	write(fd,"A",1);
	write(fd2,"B",1);
	
	int fd3 = open("dup1.dat" , O_CREAT | O_RDWR , 0666);
	printf("fd3 = %d\n", fd3);
	int fd4 = dup2(fd,fd3);
	printf("fd4 = %d\n", fd4);
	write(fd3,"hhh",3);
	close(fd);
	close(fd2);
}
